package com.lzc.springboot.controller;

import com.lzc.springboot.domain.Farmer;
import com.lzc.springboot.service.FarmerService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/farmer")
public class FarmerController {

  @Autowired
  private FarmerService farmerService;

  /**
   * 根据用户ID查询农户
   * @param uid
   * @return
   */
  @RequestMapping(value = "/findFarmerByUid",method = RequestMethod.GET)
  public Farmer findFarmerByUid(@RequestParam("uid") int uid){
    return farmerService.findFarmerByUid(uid);
  }

  /**
   * 修改农户信息
   * @param farmer
   */
  @RequestMapping("/changeFarmer")
  public void changeFarmer(@RequestBody Farmer farmer){
    farmerService.changeFarmer(farmer);
  }

  /**
   * 查询所有农户
   * @return
   */
  @RequestMapping("/findAllFarmer")
  public Farmer[] findAllFarmer(){
    return farmerService.findAllFarmer();
  }

  /**
   * 根据管理员输入查询农户
   * @param farmer
   * @return
   */
  @RequestMapping("/findFarmerByText")
  public Farmer[] findFarmerByText(@RequestBody Farmer farmer){
    return farmerService.findFarmerByText(farmer);
  }

  /**
   * 根据农户ID查询农户
   * @param fid
   * @return
   */
  @RequestMapping(value = "/findFarmerByFid",method = RequestMethod.GET)
  public Farmer findFarmerByFid(@RequestParam("fid") int fid){
    System.out.println(fid);
    return farmerService.findFarmerByFid(fid);
  }

  /**
   * 根据农户ID删除农户
   * @param id
   */
  @RequestMapping(value = "/delFarmerById",method = RequestMethod.GET)
  public void delFarmerById(@RequestParam("id") int id){
    farmerService.delFarmerById(id);
  }

  /**
   * 田间农户
   * @param farmer
   */
  @RequestMapping("/addFarmer")
  void addFarmer(@RequestBody Farmer farmer){
    farmerService.addFarmer(farmer);
  }

}
